package com.xl.studentpass.filter;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: xl
 * @createTime: 2023/6/13 13:19:46
 * @program: student-pass
 * @e-mail: 2199396150@qq.com
 * @description:
 */
@Configuration
public class SaTokenFilter implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/user/loginAndRegister",
                        "/user/login",
                        "/user/sendMessage",
                        "/user/checkUserExist",
                        "/user/getKey",
                        "/index/data/**",
                        "/community/list",
                        "/community/getPostingDetailById",
                        "/images/**",
                        "/favicon.ico",
                        "/doc.html",
                        "/webjars/**",
                        "/swagger-resources",
                        "/v2/api-docs",
                        "/task/screen",
                        "/task/taskInfo",
                        "/task/orderInfo"
                );
    }

    @Bean
    public StpLogic getStpLogicJwt() {
        return new StpLogicJwtForSimple();
    }
}
